package com.hjh.gameforum.service.impl;

import com.hjh.gameforum.dto.CategoryDto;
import com.hjh.gameforum.entity.Category;
import com.hjh.gameforum.mapper.CategoryMapper;
import com.hjh.gameforum.service.CategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class CategoryServiceImpl implements CategoryService {

    private final CategoryMapper categoryMapper;
    @Override
    public void createCategory(CategoryDto categoryDto) {
        Category category = Category.builder()
                .name(categoryDto.getName())
                .description(categoryDto.getDescription())
                .build();

        categoryMapper.createCategory(category);

    }

    @Override
    public List<Category> getAllCategories() {
        return categoryMapper.getAllCategories();
    }

    @Override
    public void updateCategory(Long categoryId, CategoryDto categoryDto) {
        Category category = Category.builder()
                .categoryId(categoryId)
                .name(categoryDto.getName())
                .description(categoryDto.getDescription())
                .build();
        categoryMapper.updateCategory(category);
    }

    @Override
    public void deleteCategory(Long categoryId) {
        categoryMapper.deleteCategory(categoryId);
    }
}
